#include "stdio.h"
#include "string.h"
#include "tier.h"
#include <stdlib.h>
#include <time.h>
int main() {
  int key, guess;
  char *buf;
  srand(time(NULL));

  int times = 1;
  do {
    for (times = 1, key = rand() % 100 + 1; times++;) {
      printf("猜数字:");
      if (scanf("%s", buf) == -1) {
        fprintf(stderr, "输不起是吧\n");
        return 1;
      };
      if (sscanf(buf, "%i", &guess) != 1) {
        printf("%s 不是一个数字\n", buf);
        continue;
      }
      if (guess > key) {
        printf("太大了\n");
      } else if (guess < key) {
        printf("太小了\n");
      } else {
        printf("猜对了，您的段位是%s\n", tier(times));
        // return 0;
        break;
      }
    }
    printf("退出？[Y/n]");
    if (scanf("%s", buf) == 1 &&
        (strcmp(buf, "N") == 0 || strcmp(buf, "n") == 0))
      // return 0;
      continue;
    break;
  } while (1);
  return 0;
}
